<template>
  <base-breadcrumb :title="titleName">
    <a-spin :spinning="spinning" :tip="tips">
    <div class="container">
      <a-card>
        <div class="button-bar">
          <a-button type="primary" @click="adjustNodeFirst" :loading="loading">按预调整调整一级节点</a-button>
        </div>
        <div class="gantt-layout">
          <div class="pub-table-select-count">
            <a-icon type="info-circle" theme="twoTone" />
            <span style="margin-right: 12px">
              项目：<span class="totalNum">{{ total.projectName }} </span> |
              预调整节点共 ：<span class="totalNum">{{ total.adjusTotalNum || 0 }} 项 </span> |
              预调整一级节点共：<span class="totalNum">{{ total.adjustFirstNodeNum || 0 }} 项 </span> |
              预调整二级节点共：<span class="totalNum">{{ total.adjustSecondNodeNum || 0 }} 项 </span> |
              预调整三级节点共：<span class="totalNum">{{ total.adjustThirdNodeNum || 0 }} 项 </span>
            </span>
          </div>
          <ux-grid
            ref="bigDataTable"
            beautifyTable
            show-header-overflow
            show-body-overflow
            :height="600"
            :row-height="50"
            :treeConfig="{
              children: 'children',
              expandAll: true,
            }"
            :use-virtual="true"
            :border="false"
            :row-class-name="rowClassNames"
            @row-click="handleClickRow"
            :edit-config="{trigger: 'manual', mode: 'row'}">
            >
            <ux-table-column
              v-for="item in columns"
              :key="item.dataIndex"
              :field="item.dataIndex"
              :title="item.title"
              :width="item.width"
              :tree-node="item.dataIndex === 'name'"
              align="center"
            >
              <template v-slot="{ row }">
                <div v-if="item.scopedSlots" :title="row[item.dataIndex]">
                  <!-- 序号 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'index'">
                    <div style="text-align:center">
                      <div
                        style="text-align:right;padding:0 10px;display:flex;justify-content:space-between;direction:rtl;width:70px "
                        v-if="row.statusLights == '0'">
                        <div>{{ row.sortNum }}</div>
                        <div v-if="row.colorfulFlags=='1'"><img style="width:20px" src="../../../assets/blueFlag.png" />
                        </div>
                        <div v-if="row.colorfulFlags=='2'"><img style="width:20px"
                                                                src="../../../assets/greenFlag.png" /></div>
                        <div v-if="row.promptLights=='1'"><img style="width:20px"
                                                               src="../../../assets/icons/yellowLight.png" /></div>
                        <div v-if="row.promptLights=='2'"><img style="width:20px"
                                                               src="../../../assets/icons/redLight.png" /></div>
                      </div>
                      <div
                        style="text-align:right;padding:0 10px;display:flex;justify-content:space-between;direction:rtl;background: rgba(224, 244, 223, 1);width:70px "
                        v-if="row.statusLights == '1'">
                        <div>{{ row.sortNum }}</div>
                        <div v-if="row.colorfulFlags=='1'"><img style="width:20px" src="../../../assets/blueFlag.png" />
                        </div>
                        <div v-if="row.colorfulFlags=='2'"><img style="width:20px"
                                                                src="../../../assets/greenFlag.png" /></div>
                        <div v-if="row.promptLights=='1'"><img style="width:20px"
                                                               src="../../../assets/icons/yellowLight.png" /></div>
                        <div v-if="row.promptLights=='2'"><img style="width:20px"
                                                               src="../../../assets/icons/redLight.png" /></div>
                      </div>
                      <div
                        style="text-align:right;padding:0 10px;display:flex;justify-content:space-between;direction:rtl;background: rgba(251, 230, 232, 1);width:70px "
                        v-if="row.statusLights == '2'">
                        <div>{{ row.sortNum }}</div>
                        <div v-if="row.colorfulFlags=='1'"><img style="width:20px" src="../../../assets/blueFlag.png" />
                        </div>
                        <div v-if="row.colorfulFlags=='2'"><img style="width:20px"
                                                                src="../../../assets/greenFlag.png" /></div>
                        <div v-if="row.promptLights=='1'"><img style="width:20px"
                                                               src="../../../assets/icons/yellowLight.png" /></div>
                        <div v-if="row.promptLights=='2'"><img style="width:20px"
                                                               src="../../../assets/icons/redLight.png" /></div>
                      </div>
                      <div
                        style="text-align:right;padding:0 10px;display:flex;justify-content:space-between;direction:rtl;background: rgba(240, 153, 164, 1);width:70px "
                        v-if="row.statusLights == '3'">
                        <div>{{ row.sortNum }}</div>
                        <div v-if="row.colorfulFlags=='1'"><img style="width:20px" src="../../../assets/blueFlag.png" />
                        </div>
                        <div v-if="row.colorfulFlags=='2'"><img style="width:20px"
                                                                src="../../../assets/greenFlag.png" /></div>
                        <div v-if="row.promptLights=='1'"><img style="width:20px"
                                                               src="../../../assets/icons/yellowLight.png" /></div>
                        <div v-if="row.promptLights=='2'"><img style="width:20px"
                                                               src="../../../assets/icons/redLight.png" /></div>
                      </div>
                      <div style="width:70px;padding:0 10px;display:flex;justify-content:space-between;direction:rtl;"
                           v-if="row.statusLights!='0'&& row.statusLights!='1'&& row.statusLights!='2'&& row.statusLights!='3'">
                        {{ row.sortNum }}
                      </div>
                    </div>
                    <!-- </template> -->
                  </div>
                  <!--阶段/类别-->
                  <div class="table-form-box" v-if="item.dataIndex === 'name'">
                    <span> {{ row.name }}</span>
                  </div>
                  <!--业务事项-->
                  <div class="table-form-box" v-if="item.dataIndex === 'businessMatters'">
                    <BaseTextarea
                      v-if="row.adjustCode=='1' && row.oldLevel=='1' || row.adjustCode == '2' && allowProjectUpdateColumn"
                      placeholder="请输入"
                      @blur="changeMatter"
                      v-model="row.businessMatters"
                      :autoSize="{minRows: 2, maxRows: 2}"
                    ></BaseTextarea>
                    <span v-else>{{ row.businessMatters }}</span>
                  </div>
                  <!-- 管控级别 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'level'">
                    <a-select :getPopupContainer="getPopupContainer"
                              v-if=" (row.adjustCode=='1'  || row.colorfulFlags=='1' ||row.colorfulFlags=='2' )&& row.oldLevel=='1'&& row.adjustCode!='3'"
                              @change="(value)=>changeLevel(row,value)" v-model="row.controlLevelName" style="width:100px;height:28px">
                      <a-select-option v-for="item in nodeList" :key="item.controlLevelId">{{ item.controlLevelName }}
                      </a-select-option>
                    </a-select>
                    <template v-else>{{ row.controlLevelName }}</template>
                  </div>
                  <!-- 周期 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'duration'">
                    <BaseInputNumber
                      placeholder="请输入"
                      v-if=" (row.adjustCode=='1' || row.colorfulFlags=='1' ||row.colorfulFlags=='2') &&row.oldLevel=='1'&& row.adjustCode!='3'"
                      v-model="row.duration"
                      :min="0"
                      :max="2000"
                      @change="editduration(row)"
                    />
                    <span v-else>{{ row.duration }}</span>
                  </div>
                  <!-- 计划开始时间 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'startTime'">
                    <a-date-picker
                      placeholder="请输入"
                      v-if=" (row.adjustCode=='1' || row.colorfulFlags=='1' ||row.colorfulFlags=='2') &&row.oldLevel=='1'&& row.adjustCode!='3'"
                      v-model="row.startTime"
                      @change="(date)=>editstartTime(row,date)"
                      style="width:120px"
                    />
                    <span v-else>{{ row.startTime }}</span>
                  </div>
                  <!-- 计划完成时间 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'endTime'">
                    <span>{{ row.endTime }}</span>
                  </div>
                  <!-- 实际完成时间 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'completeTime'">
                    <span>{{ row.completeTime }}</span>
                  </div>
                  <!--            完成标准-->
                  <div v-if="item.dataIndex === 'completeStandard'">
                    <div class="table-form-box">
                      <BaseTextarea
                        v-if="row.adjustCode=='1' && row.oldLevel=='1' || row.adjustCode == '2' && allowProjectUpdateColumn"
                        placeholder="请输入"
                        @blur="changecompleteStandard"
                        v-model="row.completeStandard"
                        :autoSize="{minRows: 2, maxRows: 2}"
                      ></BaseTextarea>
                      <span v-else>{{ row.completeStandard }}</span>
                    </div>
                  </div>
                  <!-- 验证资料 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'verifyDoc'">
                    <BaseTextarea
                      v-if="row.adjustCode=='1'&& row.oldLevel=='1' || row.adjustCode == '2' && allowProjectUpdateColumn"
                      @blur="changeverifyDoc"
                      placeholder="请输入"
                      v-model="row.verifyDoc"
                      :autoSize="{minRows: 2, maxRows: 2}"
                    ></BaseTextarea>
                    <span v-else>{{ row.verifyDoc }}</span>
                  </div>
                  <!-- 第一责任人 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'firstResponsible'" :title="row.firstResponsibleName">
                    <a v-if=" row.adjustCode=='1' && row.oldLevel=='1' || row.adjustCode == '2' && allowProjectUpdateColumn" @click="handleBind(row)">
                      {{ row.firstResponsibleName ? `重新选择(${row.firstResponsibleName})` : '选择第一责任人' }}
                    </a>
                    <span v-else>{{ row.firstResponsibleName }}</span>
                  </div>
                  <!-- 直接责任人 -->
                  <div class="table-form-box" v-if="item.dataIndex === 'responsible'">
                    <a-select :getPopupContainer="getPopupContainer"
                              v-if=" (row.adjustCode=='1' || row.colorfulFlags=='1' ||row.colorfulFlags=='2') && row.oldLevel=='1'&& row.adjustCode!='3'"
                              @select="changeRespons" v-model="row.responsibleName" style="width:100px">
                      <a-spin v-if="loading" slot="notFoundContent" size="small" />
                      <a-select-option v-for="item in responsLists" :key="item.employeeId" :value="item.employeeName">
                        {{ item.employeeName }}
                      </a-select-option>
                    </a-select>
                    <template v-else>{{ row.responsibleName }}</template>
                  </div>
                </div>
                <span v-else :title="row[item.dataIndex]">
                  {{ row[item.dataIndex] }}
                </span>
              </template>
            </ux-table-column>
            <ux-table-column
              fixed="right"
              width="220"
              title="操作">
              <template v-slot="{ row }">
              <span v-if="row.oldLevel=='1'">
                <a v-if="row.adjustCode=='1'" @click="saveAdd(row)">保存新增</a>
                <a v-if="row.adjustCode=='2'" @click="saveAdjust(row)">保存信息调整</a>
                <a v-if="row.adjustCode=='3'" @click="saveDelete(row)">保存删除</a>
              <a-divider v-if="row.level=='4' && row.adjustCode && row.oldLevel=='1'" type="vertical" />
              <a v-if="row.level=='4'" @click="showMoreList(row)">更多</a> 
              </span>
              </template>
            </ux-table-column>
          </ux-grid>
        </div>
        <div style="float:right;margin-top: 20px;margin-bottom: 20px;">
          <a-button
            :loading="loading"
            @click="saveAndSubmit"
            :disabled="type == 'view' || type == 'approve'"
            style="margin-left: 12px"
            type="primary"
          >提交
          </a-button>
          <a-button class="button" @click="goBack()" type="default">关闭</a-button>
        </div>
      </a-card>
    </div>
    <MoreList
      :visible="showMoreListVisible"
      :moreListData="moreListData"
      @closeMoreList="closeMoreList"
    ></MoreList>
    <modal
      :id="currentId"
      :orgQuery="orgQuery"
      :screening="true"
      :visible="true"
      v-if="bindOrgVisible"
      @handleCancelFirstRes="handleCancelFirstRes"
      @job-selected="handleOk"
    />
    </a-spin>
  </base-breadcrumb>
</template>
<script>
import {
  editTemplateNode,
  getNodeControl
} from '@/api/template'
import Gantt from '../gantt/gantt'
import TaskTemplateModal from '../gantt/template-modal'
import locale from 'ant-design-vue/es/date-picker/locale/zh_CN'
import * as moment from 'moment'
import EditableCell from './EditableCell'
import { getPreAdjustDetail, addNode, deleteWork, editeWork, adjustWorks, saveAndSubmit } from '@/api/adjust'
import { getOrganizeUserList } from '@/api/commons'
import modal from '@/components/SelectJobs' // 第一责任人
import { UTable, UTableColumn, UxGrid, UxTableColumn } from 'umy-ui'
import MoreList from '../adjust/list/moreListModal.vue'
import { getProjects } from '@/api/construction/planInput'
import Vue from 'vue'
// import Cell from './cell'
const columns = [
  {
    title: '序号',
    width: 80,
    align: 'center',
    dataIndex: 'index',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '阶段/类别',
    dataIndex: 'name',
    scopedSlots: { customRender: 'name' },
    width: 250
  },
  {
    title: '业务事项',
    align: 'center',
    dataIndex: 'businessMatters',
    width: 320,
    scopedSlots: { customRender: 'businessMatters' }
  },
  {
    title: '管控级别',
    align: 'center',
    dataIndex: 'level',
    scopedSlots: { customRender: 'level' },
    width: 120
  },
  {
    title: '周期',
    dataIndex: 'duration',
    align: 'center',
    width: 120,
    scopedSlots: { customRender: 'duration' }
  },
  {
    title: '计划开始时间',
    dataIndex: 'startTime',
    align: 'center',
    width: 150,
    scopedSlots: { customRender: 'startTime' }
  },
  {
    title: '计划完成时间',
    dataIndex: 'endTime',
    align: 'center',
    width: 120,
    scopedSlots: { customRender: 'endTime' }
  },
  {
    title: '实际完成时间',
    dataIndex: 'completeTime',
    align: 'center',
    width: 120,
    scopedSlots: { customRender: 'completeTime' }
  },
  {
    title: '完成标准',
    dataIndex: 'completeStandard',
    width: 450,
    align: 'center',
    scopedSlots: { customRender: 'completeStandard' },
    ellipsis: true
  },
  {
    title: '验证资料',
    dataIndex: 'verifyDoc',
    align: 'center',
    width: 350,
    scopedSlots: { customRender: 'verifyDoc' },
    ellipsis: true
  },
  {
    title: '第一责任人',
    align: 'center',
    dataIndex: 'firstResponsible',
    width: 350,
    scopedSlots: { customRender: 'firstResponsible' },
    ellipsis: true
  },
  {
    title: '直接责任人',
    width: 120,
    align: 'center',
    dataIndex: 'responsible',
    scopedSlots: { customRender: 'responsible' },
    ellipsis: true
  },
  {
    title: '节点状态',
    align: 'center',
    width: 120,
    dataIndex: 'nodeStatus',
    ellipsis: true
  },
  {
    title: '调整情况',
    width: 120,
    align: 'center',
    dataIndex: 'adjustInformation',
    ellipsis: true
  }
]
export default {
  name: 'DhtmlxGantt',
  components: {
    Gantt,
    TaskTemplateModal,
    EditableCell,
    modal,
    MoreList,
    umiTable: UTable,
    UTableColumn,
    UxGrid,
    UxTableColumn
  },
  data() {
    return {
      tips:'数据加载中...',
      spinning: false,
      orgQuery: {},
      levelOption: '',
      tableData: [],
      titleName: '',
      startDates: '',
      projectId: '',
      locale,
      total: {},
      bindOrgVisible: false,
      currentId: '',
      tasks: { data: [], links: [] },
      columns,
      templateId: '',
      loading: false,
      addLevel: '',
      showMoreListVisible: false,
      selectResponsible: {},
      resultData: {},
      responsLists: [],
      saveSelectRows: [],
      ganttColumns: [],
      firstResponsible: [],
      endTime: '',
      selectNodeLevel: '',
      startTime: '',
      preTasks: [],
      type: '',
      editable: false,
      selectLevel: '',
      taskType: 'task',
      modalTitle: '新增节点',
      confirmLoading: false,
      nodeList: '',
      moreListData: [],
      addVisible: false,
      visible: false,
      selectId: '',
      editingKey: '',
      taskTemplateVisible: false,
      plugins: {
        undo: true,
        drag_timeline: true
      },
      messages: [],
      selectedTask: null,
      rangeConfig: {
        rules: [{ type: 'array', required: true, message: '请选择计划日期!' }]
      }
    }
  },
  beforeCreate() {
    this.form = this.$form.createForm(this, {})
  },
  created() {
    const userInfo = Vue.getAcloudProvider().getUserInfo()
    this.currentId = userInfo.id
    this.planId = this.$route.query.id
    this.type = this.$route.query.type
    this.getPreAdjustDetail(true)
    this.getNodeControl()
    localStorage.removeItem('task')
    localStorage.removeItem('link')
    this.tasks.data = []
    this.tasks.links = []
    this.ganttColumns = [
      {
        name: 'sortNum', label: '序号', align: 'center', tree: true, width: 0, template: function(obj) {
          return obj.$index + 1
        }
      }
    ]
    // this.selectId = this.tableData[0].nodeId
  },
  mounted() {
    console.log(this.tableData)
  },
  watch: {
    tableData(list) {
      if (this.$refs.bigDataTable) {
        // 获取之前展开数据
        const expandRecords = this.$refs.bigDataTable.getTreeExpandRecords()
        const scrollTop = this.$refs.bigDataTable.tableExample().getScroll().scrollTop
        // 获取之前滚动高度
        // 加载数据
        this.$refs.bigDataTable.reloadData(list).then(() => {
          // 数据加载完成出现之后，打开之前的展开行
          const expandKeys = expandRecords.map(item => item.id)
          const needExpandRecords = []
          // 遍历tree，找到需要展开的数据，再依次展开
          const deepFn = (list) => {
            list && list.forEach(item => {
              if (expandKeys.includes(item.id)) {
                needExpandRecords.push(item)
              }
              item.children && deepFn(item.children)
            })
          }
          deepFn(this.tableData)
          needExpandRecords.forEach(row => {
            this.$refs.bigDataTable.setTreeExpand(row, true)
          })
          // 还原之前滚动高度
          this.$nextTick(() => {
            this.$refs.bigDataTable.pagingScrollTopLeft(scrollTop)
          })
        })
      }
    }
  },
  computed: {
    allowProjectUpdateColumn() {
      try {
        const allowList = JSON.parse(sessionStorage.getItem('allowProjectList'))
        return allowList.includes(this.projectId)
      } catch {
        return false
      }
    }
  },
  methods: {
    // 更多
    showMoreList(record) {
      this.showMoreListVisible = true
      this.moreListData = record.childrenAdjust
    },
    // 关闭更多弹窗
    closeMoreList() {
      this.showMoreListVisible = false
    },
    // 第一责任人
    handleCancelBindOrg(val) {
      // this.bindOrgVisible=val
    },
    handleCancelFirstRes() {
      this.bindOrgVisible = false
    },
    handleBind(record) {
      this.bindOrgVisible = true
      this.firstResponsibleData = record
    },
    handleOk(value) {
      this.bindOrgVisible = false
      this.firstResponsibleData.firstResponsibleName = value.name
      this.firstResponsibleData.firstResponsibleId = value.id
      this.firstResponsibleData.firstResId = value.id
    },

    saveAndSubmit() {
      this.loading = true
      saveAndSubmit({ adjustNodeLevel: '1', planId: this.planId }).then(res => {
        if (res.code = '200') {
          this.loading = false
          this.$message.success('保存提交成功')
          this.$router.replace('/project/adjust')
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 保存新增
    saveAdd(record) {
      record.planId = this.planId
      record.endTime = this.endTime
      record.adjustType = '1'
      if (!record.startTime) {
        record.startTime = this.startTime
      }
      record.workId = record.id
      record.controlLevelName = null
      editeWork(record).then(res => {
        if (res) {
          this.getPreAdjustDetail()
        }
        if (res.code = '200') {
          this.$message.success('保存成功')
        }
      })
    },
    // 保存信息调整
    saveAdjust(record) {
      record.planId = this.planId
      record.endTime = this.endTime
      record.adjustType = '1'
      if (!record.startTime) {
        record.startTime = this.startTime
      }
      record.workId = record.id
      record.controlLevelName = null
      editeWork(record).then(res => {
        if (res) {
          this.getPreAdjustDetail()
        }
        if (res.code = '200') {
          this.$message.success('保存成功')
        }
      })
    },
    // 保存删除
    saveDelete(record) {
      if (record.level == '1' || record.level == '2' || record.level == '3') {
        this.$message.error('不能删除')
        return false
      } else {
        this.loading = true
        let _this = this
        this.$confirm({
          okText: '删除',
          okType: 'danger',
          cancelText: '取消',
          title: '确定删除当前节点?',
          onOk() {
            let data = {}
            data = {
              planId: _this.planId,
              parentId: record.parentId,
              adjustId: record.id,
              adjustType: '1',
              isAdjustAdd: record.isAdjustAdd,
              oldWorkId: record.oldWorkId
            }
            return new Promise((resolve, reject)=>{
              deleteWork(data).then((res) => {
                if (res) {
                  _this.getPreAdjustDetail()
                }
                if (res.code = '200') {
                  _this.loading = false
                  _this.$message.success('节点删除成功')
                }
                resolve()
              }).catch(() => {
                _this.loading = false
                reject()
              })
            })
          },
          onCancel() {
            _this.loading = false
          },
          class: 'test'
        })
      }
    },

    adjustNodeFirst() {
      this.loading = true
      let adjustNodeLevel
      if (this.type == '4') {
        adjustNodeLevel = 1
      } else if (this.type == '5') {
        adjustNodeLevel = 2
      } else if (this.type = '6') {
        adjustNodeLevel = 3
      }
      let _this = this
      adjustWorks({
        adjustNodeLevel: adjustNodeLevel,
        planId: _this.planId
      }).then(res => {
        //   _this.$message.success("调整成功")
        if (res.code = '200') {
          _this.loading = false
          _this.$message.success('调整成功')
          _this.getPreAdjustDetail()
        }
      }).catch(() => {
        _this.loading = false
      })
    },
    // 直接责任人查询
    getOrganizePeopleList() {
      this.loading = true
      getOrganizeUserList({ id: this.projectId }).then(res => {
        this.responsLists = res.data
        this.loading = false
      })
    },
    getNodeControl() {
      getNodeControl().then((res) => {
        this.nodeList = res.data
      })
    },
    // 标准开始时间
    editstartTime(record,dateMoment) {
      this.startTime = dateMoment.format('yyyy-MM-DD')
      record.startTime = this.startTime
      if (record.duration) {
        record.endTime = dateMoment.add(record.duration, 'd').format('yyyy-MM-DD')
      }
    },
    // 周期
    editduration(record) {
      const startTime = moment(record.startTime, 'yyyy-MM-DD')
      const endTime = startTime.add(record.duration, 'd')
      record.endTime = endTime.format('yyyy-MM-DD')
    },
    // 验证资料
    changeverifyDoc(e) {
      this.saveSelectRows.verifyDoc = e.target.value
      let data = {}
      data = {
        templateId: this.templateId,
        nodeId: this.selectedData.nodeId,
        verifyDoc: this.saveSelectRows.verifyDoc
      }
    },
    // 完成标准
    changecompleteStandard(e) {
      this.saveSelectRows.completeStandard = e.target.value
      let data = {}
      data = {
        templateId: this.templateId,
        nodeId: this.selectedData.nodeId,
        completeStandard: this.saveSelectRows.completeStandard
      }
    },
    // 管控节点
    changeLevel(row,value) {
      row.controlLevelId = value
    },
    // 获取模板
    getPreAdjustDetail(needBaseInfos) {
      this.spinning = true
      getPreAdjustDetail({ planId: this.planId }).then((res) => {
        this.tableData = res.data.list
        this.total = res.data
        this.projectId = res.data.projectId
        if(needBaseInfos){
          this.getProjectDepts()
          this.getOrganizePeopleList()
        }
        this.spinning = false
      }).catch(()=>{
        this.spinning = false
      })
    },
    getProjectDepts() {
      const projectId = this.projectId
      const params = {
        projectIds: [projectId]
      }
      getProjects(params).then((res) => {
        this.orgQuery.ids = res.data[0].orgId
      })
    },
    changeMatter(e, record) {
      this.saveSelectRows.businessMatters = e.target.value
      let data = {}
      data = {
        templateId: this.templateId,
        nodeId: this.selectedData.nodeId,
        name: this.saveSelectRows.businessMatters
      }
    },
    changeRespons(value) {
      // console.log(value)
      // value.responsible={
      //   label:value.label,
      //   key:value.key
      // }
    },
    /**
     * 控制umi-table的点击
     */
    handleClickRow(record) {
      this.selectId = record.id
      this.selectedData = record
      this.rowClassNames(record)
    },
    dataListToTree() {
      let dataList = this.tableData
      const dataMaps = {}
      const tree = []
      const dataListCopy = []
      dataList.forEach(data => {
        const copy = { ...data, start_date: data.startTime, parent: data.parent, children: data.children }
        dataMaps[copy.id] = copy
        dataListCopy.push(copy)
      })
      dataListCopy.forEach(data => {
        if (data.parent) {
          const parent = dataMaps[data.parent]
          if (parent) {
            parent.children.push(data)
          } else {
            data.parent = null
            tree.push(data)
          }
        } else {
          tree.push(data)
        }
      })
      return tree
    },
    // 新增同级节点
    addNode() {
      let _this = this
      //如果选择的是一级二级三级节点
      if (_this.selectedData.level != '4') {
        this.$message.error('此节点不可新增节点')
        return false
      } else {
        this.$confirm({
          okText: '确定',
          cancelText: '取消',
          title: '确定新增节点?',
          onOk() {
            addNode({
              parentId: _this.selectedData.parentId,
              planId: _this.planId,
              adjustType: '0'
            }).then(res => {
              if (res) {
                _this.getPreAdjustDetail()
              }
              if (res.code == '200') {
                _this.$message.success('新增成功')
              }
            })
          }
        })
      }
    },
    getPopupContainer(triggerNode) {
      return triggerNode.parentNode
    },
    rowClassNames(record) {
      if (this.selectId == record.id) {
        return 'clickRowStyle'
      }
    },
    goBack() {
      this.$multiTab.close(this.$route.fullpath)
    }
  }
}
</script>

<style scoped>
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

/deep/ .ant-table-body .clickRowStyle {
  background-color: rgb(230, 243, 252);
}

/deep/ .ant-pro-basicLayout-children-content-wrap {
  flex: 1;
}

.gantt-layout {
  position: relative;
}

/deep/ .ant-table-thead th {
  height: 60px;
  line-height: 60px;
  padding: 0;
}

/deep/ .ant-table-placeholder {
  height: 600px;
}

/deep/ .gantt-layout .ant-table-body {
  min-height: 600px;
}

/deep/ .ant-drawer-content-wrapper {
  box-shadow: none !important;
}

/deep/ .ant-table-selection-column {
  width: 40px;
}

.button-bar {
  margin-bottom: 10px;
}

.button {
  margin: 0 10px;
}

.button-bar > button:not(:first-child) {
  margin-left: 10px;
}

/deep/ .ant-modal-body {
  padding: 0
}

td {
  display: flex;
}

input[type='text'], input[type='password'], input[type='number'], textarea {
  width: 100%;
  height: 28px
}

.ant-calendar-picker {
  width: 200px;
  height: 28px
}

.ant-cascader-picker {
  width: 100%;
  height: 28px
}

form .ant-select, form .ant-cascader-picker {
  width: 100%;
  height: 28px !important
}

.ant-calendar-picker-input.ant-input {
  width: 200px;
  height: 28px !important
}

/deep/ .ant-card-bordered {
  margin-top: 0
}

/deep/ .ant-table-tbody > tr > td {
  padding: 5px !important;
}

/deep/ .elx-table.elx-editable .elx-body--column, .elx-table.elx-editable .elx-body--column.col--actived {
  padding: 5px 0 !important
}

/deep/ .ant-select-selection--single {
  height: 28px !important
}

/deep/ textarea.ant-input {
  height: 45px !important;
  min-height: 45px !important
}
</style>
